package main

import (
	"fmt"
	"github.com/gomodule/redigo/redis"
)

var pool redis.Pool

func init() {
	pool = redis.Pool {
		MaxIdle: 8,
		MaxActive: 0,
		IdleTimeout: 300,
		Dial: func() (redis.Conn, error) {
			return redis.Dial("tcp", "192.168.3.108:6379")
		},
	}
}
 
func main() {
	conn := pool.Get()  // 从池里获取一个连接使用
	defer conn.Close()  // 还是记得要关闭连接
	resCon, err := conn.Do("Set", "school", "SHHS")
	if err != nil {
		fmt.Println("Redis Set ERROR:", err)
		return
	}
	fmt.Println(resCon)  // 返回值是OK没什么用

	resGet, err := redis.String(conn.Do("Get", "school"))
	if err != nil {
		fmt.Println("Redis Get ERROR:", err)
		return
	}
	fmt.Println(resGet)
	pool.Close()  // 关闭pool
}